package com.cmcc.shared.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import com.cmcc.shared.R
import com.cmcc.shared.SdkManager
import com.cmcc.shared.databinding.WidgetCardDriverBinding

/**
 * Author: jiangxin
 * Date: 2019/11/20
 * Description:
 */
class DriverCard(context: Context, attrs: AttributeSet? = null) : FrameLayout(context, attrs) {

    private var binding: WidgetCardDriverBinding

    init {
        binding = WidgetCardDriverBinding.inflate(LayoutInflater.from(context), this, false)
        addView(binding.root)

    }

    fun loadSuccess(){
        binding.failedLayout.visibility = View.GONE
        binding.loadingLayout.visibility = View.GONE
        binding.successLayout.visibility = View.VISIBLE
    }

    fun loading(){
        binding.failedLayout.visibility = View.GONE
        binding.loadingLayout.visibility = View.VISIBLE
        binding.successLayout.visibility = View.GONE
    }

    fun loadFailed(){
        binding.failedLayout.visibility = View.GONE
        binding.loadingLayout.visibility = View.GONE
        binding.successLayout.visibility = View.GONE
    }

    fun setValue(orderCountToday: Int, totalAmountToday: Double) {
        binding.orderCount.text = orderCountToday.toString()
        binding.todayIncome.text = "HK$: $totalAmountToday"
    }

    fun changeStatus(status: Int) {
        if (status == 0)//休班中
            when(SdkManager.getLanguage()){
                0->{
                    binding.changeStatus.text = "Take an order"
                }
                1->{
                    binding.changeStatus.text = "去接单"
                }
                2->{
                    binding.changeStatus.text = "去接單"
                }
            }
        else
            when(SdkManager.getLanguage()){
                0->{
                    binding.changeStatus.text = "Off-duty"
                }
                1->{
                    binding.changeStatus.text = "休班"
                }
                2->{
                    binding.changeStatus.text = "休班"
                }
            }
    }

    fun setStatusChangeClickListener(listener: OnClickListener) {
        binding.changeStatus.setOnClickListener(listener)
    }
}